package com.sy.simpleegg.mvp.model

import com.sy.simpleegg.base.BaseModel
import com.sy.simpleegg.bean.RecordOrderBean
import com.sy.simpleegg.ext.logFile
import com.sy.simpleegg.mvp.contract.RecordContract
import com.sy.simpleegg.room.RoomUtil

class RecordModel : BaseModel(), RecordContract.Model {
    override suspend fun getOrder(date: String): MutableList<RecordOrderBean> {
        return try {
            if (date.length == 8) {
                val targetDate = "${date.substring(0, 4)}-${date.substring(4, 6)}-${date.substring(6, 8)}"
                val recordList: MutableList<RecordOrderBean> = mutableListOf()
                val dataList = RoomUtil.orderGetByDate(targetDate)?.run {
                    forEach { orderEntity ->
                        recordList.add(
                            RecordOrderBean(
                                orderEntity.date,
                                orderEntity.money,
                                orderEntity.amount,
                                true,
                                orderEntity.amount
                            )
                        )
                    }
                }
                recordList
            }else{
                mutableListOf()
            }
        } catch (e: Exception) {
            e.printStackTrace()
            logFile("获取出币记录异常：${e.message}")
            mutableListOf<RecordOrderBean>()
        }
    }

}